<?php
class Admin_Form_UserLogin extends TBB_Form
{	
	public function init()
	{
//		// add path to custom validators
//		$this->addElementPrefixPath('Home_Validate', 
//						APPLICATION_PATH . '/modules/home/models/validate/',
//						'validate');

		$this->addAttribs(array(
			'class' => 'span-6',
		));
		
		// create id element
		$id = $this->_createUserIDElement ();
		
		// create username element
		$username = $this->_createUsernameElement();
				
		// create password element
		$password = $this->_createPasswordElement();		
		
		// create login button
		$login = $this->_createLoginButton();

		$this->addElements(array($id, $username, $password, $login));
		$this->addDisplayGroup(array('id', 'username', 'password', 'login'), 'userLoginGroup', array('class' => 'span-6'));		
		
		// set decorators for all elements and display groups
		$this->setDecorators($this->_formDecorators);
		$this->setDisplayGroupDecorators($this->_displayGroupDecorators);
		
		// overwrite fieldset class
		$this->getDisplayGroup('userLoginGroup')->setAttribs(array('class' => 'fieldsetFormNav'));
	}
	
	private function _createLoginButton()
	{
		$login = $this->createElement('submit', 'login');
		$login->setDecorators(array(
			'ViewHelper',
			array(
				'HtmlTag',
				array('tag' => 'dd', 'id' => 'login')
		)));
		$login->setLabel('Đăng nhập');
		$login->setAttribs(array(
			'class' => 'span-3 last submitDecorator',
						
		));	
		return $login;
	}	
	
	private function _createPasswordElement()
	{
		$password = $this->createElement('password', 'password');
		$password->setLabel('Mật khẩu: ');
		$password->setRequired(true);
		$password->addErrorMessage('Làm ơn nhập mật khẩu.');
		$password->setAttribs(array(
			'class' => 'span-4',

		));
		$password->getDecorator('Label')->setOption('class', 'column span-3 labelDecorator');
		$password->getDecorator('Errors')->setOption('class', 'span-4 errorDecorator');
		return $password;
	}
	
	private function _createUsernameElement()
	{
		$username = $this->createElement('text', 'username');
		$username->setLabel('Tên đăng nhập: ');
		$username->setRequired(true);
		$username->addFilter('StripTags');
		$username->addErrorMessage('Làm ơn nhập tên đăng nhập.');
		$username->setAttribs(array(
			'class' => 'span-4',

		));
		$username->getDecorator('Label')->setOption('class', 'column span-3 labelDecorator');
		$username->getDecorator('Label')->setOption('style', 'margin-top: 0'); // special here: margin-top: 0
		$username->getDecorator('Errors')->setOption('class', 'span-4 errorDecorator');
		return $username;
	}

	private function _createUserIDElement() {
		$id = $this->createElement('hidden', 'id');
		$id->setDecorators($this->_hiddenDecorators);
		$id->setAttribs(array(
			'class' => 'span-4',
		));
		return $id;
	}
}